var areaLonLat = {
	"500114":[108.78008, 29.453831,10],
	"500118":[105.91348,29.374296,11],
	"500227":[106.231497,29.599161,10],
	"500102":[107.406588,29.711936,11],
	"500242":[108.834731,28.868262,10],
	"500102":[107.346797,29.712438,10],
	"500110":[106.65854,28.987919,10],
	"500116":[106.276881,29.277175,10]
}

//运行监控主函数
function Monitor() { var that = this; }

Monitor.prototype.tempSlider = null;
Monitor.prototype.preSlider = null;
Monitor.prototype.soilSlider = null;
Monitor.prototype.tempImgHolder = null;
Monitor.prototype.preImgHolder = null;
Monitor.prototype.soilImgHolder = null;
Monitor.prototype.timeTemp = null;
Monitor.prototype.timePre = null;
Monitor.prototype.timeSoil = null;
Monitor.prototype.tempImgs = [];
Monitor.prototype.preImgs = [];
Monitor.prototype.soilImgs = [];

//统计元素
Monitor.prototype.c_farmland = null;
Monitor.prototype.c_farmland_m = null;
Monitor.prototype.c_agrinfo = null;
Monitor.prototype.c_agrinfo_m = null;
Monitor.prototype.c_vip = null;
Monitor.prototype.c_vip_m = null;
Monitor.prototype.c_expert = null;
Monitor.prototype.c_expert_m = null;
Monitor.prototype.c_adv = null;
Monitor.prototype.c_adv_m = null;


Monitor.getLiveImgUrls  = function(eletype,count,areaname){
	var monitor = new Monitor();
	var userInfo = monitor.getUserInfo();
	//areaname = areaname ?  "_"+areaname : "_zhongqingshi";
	areaname = "_"+userInfo.enname;
	eletype = eletype || "T";
	var imgs = [];
	var dt = new Date();
	var y = dt.getFullYear(),
		m = dt.getMonth()+ 1,
		d = dt.getDate(),
		h = dt.getHours()-1;
	var rh = h,
		rd = d;
	for (var i = 0; i < 6; i++) {
		if (h >= i) {
			var rh = h - i;
		} else {
			var rh = 24 + (h - i);
			var rd = d - 1;
		}

		var imgName = y.toString().substring(2) + "" + (m < 10 ? "0" + m : m) + "" + (rd < 10 ? "0" + rd : rd) + (rh < 10 ? "0" + rh : rh) + areaname+".jpg";
		imgs.push(Monitor.server.imgPath + eletype+"/" + imgName);
	}
	return imgs;
}

Monitor.cutstr = function(ostr,len){
	return ostr.length >=len ? ostr.substring(0,len)+"...": ostr;
}

Monitor.prototype.initIndex = function(){
	//服务情况监控
	this.modelProducts 			= $('.modelProducts').find('p');
	this.indexC                 = $('.cropTag').find('p');
	this.productModel           = $('.productModel').find('p');
	// this.climateDivision 		= $('.climateDivision').find('p');
	// this.meteorologicalDisaster = $('.meteorologicalDisaster').find('p');
	this.expertExperience 		= $('.expertExperience').find('p');
	this.userRegistration 	    = $('.userRegistration').find('p');
	this.expertRegistration 	= $('.expertRegistration').find('p');
	this.expertsAreActive 		= $('.expertsAreActive').find('p');
	this.expertInteraction 		= $('.expertInteraction').find('p');
	this.farmerRegistration 	= $('.farmerRegistration').find('p');
	this.farmersStation 		= $('.farmersStation').find('p');
	this.agriculturalUpload 	= $('.agriculturalUpload').find('p');
	this.serviceFarmland 		= $('.serviceFarmland').find('p');
	this.farmersAdvisoryinfo    = $('.farmersAdvisoryinfo').find('p');
	this.publicproduct          = $('.publicproduct').find('p');
	this.modelProducts_ 		= $('.modelProducts').find('span');
	this.indexC_                = $('.cropTag').find('span');
	this.productModel_          = $('.productModel').find('span');
	// this.climateDivision_ 		= $('.climateDivision').find('span');
	// this.meteorologicalDisaster_= $('.meteorologicalDisaster').find('span');
	this.expertExperience_ 		= $('.expertExperience').find('span');
	this.userRegistration_	    = $('.userRegistration').find('span');
	this.expertRegistration_ 	= $('.expertRegistration').find('span');
	this.expertsAreActive_ 		= $('.expertsAreActive').find('span');
	this.expertInteraction_ 	= $('.expertInteraction').find('span');
	this.farmerRegistration_ 	= $('.farmerRegistration').find('span');
	this.farmersStation_ 		= $('.farmersStation').find('span');
	this.agriculturalUpload_ 	= $('.agriculturalUpload').find('span');
	this.serviceFarmland_ 		= $('.serviceFarmland').find('span');
	this.farmersAdvisoryinfo_	= $('.farmersAdvisoryinfo').find('span');
	this.publicproduct_         = $('.publicproduct').find('span');
}

/************
 * 运行监控获取小时温度
 */
Monitor.server = {
	imgs: "http://183.230.183.18:8088/",
	imgPath: "http://183.230.183.18:8088/pisaimage/stationlive/",
	apiPath: "http://183.230.183.18:8088/SPPMDataService/services/data/query"
}

window.login;
Monitor.prototype.login = function(loginname,password){
	var oThis = this;
	var bool;
	$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.login","CustomParams":{loginname:"'+ loginname +'",password:"'+ password +'"},"Type":2}'},function(data){
		if(data.length>0){
			$.cookie('_userinfo_', JSON.stringify(data),{ expires: 7 });
			top.window.location.href = "index.html";
			bool=true;
		}else{
			bool=false;
			alert('用户名或密码错误');
		}
		if(!window.localStorage){
         	alert("浏览器支持localstorage");
        }else{
            var storage=window.localStorage;
            storage.boolea=bool;
        }
	});
}
Monitor.prototype.loginout = function(callback){
	var oThis = this;
	$.cookie('_userinfo_', null);
	var storage = window.localStorage;
       storage.boolea = false;
       storage = null;

	top.window.location.href = "index.html";
	if(callback) callback();
}

Monitor.prototype.getUserInfo = function(callback){
	var oThis = this;
	var _userinfo_ = $.cookie("_userinfo_");
	if(_userinfo_ == null || _userinfo_ == ""){
		return {areacode:'50', loginname:'guest', enname:'zhongqingshi', areaname:'重庆市'};
	}else{
		return JSON.parse(_userinfo_)[0];
	}
}

// 获取userpw
Monitor.prototype.getLoginName = function() {
	$("#userPsw").remove();
	$(".fileDown").remove();
	$.post(Monitor.server.apiPath, {param:'{"Function":"monitor.getLoginName","CustomParams":{},"Type":2}'}, function(data){
		var html =  "<div id=\"userPsw\">"
						+"<h>重庆市</h>"
						+"<ul></ul>"
					+"</div>";
		$(".nav").append(html);
		var UserInfo = Monitor.prototype.getUserInfo();
		$("#userPsw").find('h').text(UserInfo.areaname);
		for (var x = 0; x < data.length; x++) {
			var litem = "<li loginname=\""+ data[x].loginname +"\">"+ data[x].areaname +"</li>";
			$("#userPsw").find('ul').append(litem);
		}
		$("#userPsw").find('h').on('click', function(){
			if ($("#userPsw").find('ul').css('display') == 'block') {
				$("#userPsw").find('ul').hide();
			}else{
				$("#userPsw").find('ul').show();
			}
		});
		$("#userPsw").find('li').on('click', function(){
			var loginname = $(this).attr('loginName');
			Monitor.prototype.withoutpassword(loginname);
		});
	});
	$(".statistics_list").find('.head').append('<a class=\"fileDown\" href=\"http://pisaworkstation.ngrok.cc/download/download\">文档下载</a>');
}

Monitor.prototype.getWorkStation = function(areacode,callback) {
	var oThis =this;
	$.post(Monitor.server.apiPath,
			{param:'{"Function":"monitor.getworkstation","CustomParams":{areacode:'+ areacode +'},"Type":2}'},
			function(data) {
				if(callback) callback.call(oThis,data);
		localStorage.workStation = JSON.stringify(data);
	});
}

Monitor.prototype.withoutpassword = function(loginname) {
	$.post(Monitor.server.apiPath,
			{param:'{"Function":"monitor.login.withoutpassword","CustomParams":{loginname:'+loginname+'},"Type":2}'},
			function(data){
		$.cookie('_userinfo_', JSON.stringify(data),{ expires: 7 });
		top.window.location.href = "index.html";
	});
}

Monitor.prototype.createImgSoruce = function(count, imgs) {
	var dt = new Date();
	var y = dt.getFullYear(),
		m = dt.getMonth() +1,
		d = dt.getDate(),
		h = dt.getHours()-1;
	var rh = h,
		rd = d;
	for (var i = 0; i < 6; i++) {
		if (h >= i) {
			var rh = h - i;
		} else {
			var rh = 24 + (h - i);
			var rd = d - 1;
		}
		var userInfo = this.getUserInfo();
		
		return y.toString().substring(2) + "" + (m < 10 ? "0" + m : m) + "" + (rd < 10 ? "0" + rd : rd) + (rh < 10 ? "0" + rh : rh) + "_"+ userInfo.enname +".jpg";
	}

	//alert(JSON.stringify(Monitor.tempImgs));
}

Monitor.prototype.showHoureTemp = function() {
	var dt = new Date();
	var y = dt.getFullYear(),
		m = dt.getMonth()+ 1,
		d = dt.getDate(),
		h = dt.getHours()-1;
	var rh = h,
		rd = d;
	for (var i = 0; i < 6; i++) {
		if (h >= i) {
			var rh = h - i;
		} else {
			var rh = 24 + (h - i);
			var rd = d - 1;
		}
		var userInfo = this.getUserInfo();
		var imgName = y.toString().substring(2) + "" + (m < 10 ? "0" + m : m) + "" + (rd < 10 ? "0" + rd : rd) + (rh < 10 ? "0" + rh : rh) + "_"+ userInfo.enname +".jpg";
		this.tempImgs.push(Monitor.server.imgPath + "T/" + imgName);
		
	}
	$(".wrap ul li").eq(0).find('img').attr('src', this.tempImgs[0]);
	// this.timeTemp.innerHTML = userInfo.areaname+ h +"时";
}

/*************
 * 运行监控获取小时降水
 */
Monitor.prototype.showHourePre = function() {
	var dt = new Date();
	var y = dt.getFullYear(),
		m = dt.getMonth()+1,
		d = dt.getDate(),
		h = dt.getHours()-1;
	var rh = h,
		rd = d;
	for (var i = 0; i < 6; i++) {
		if (h >= i) {
			var rh = h - i;
		} else {
			var rh = 24 + (h - i);
			var rd = d - 1;
		}
		var userInfo = this.getUserInfo();
		var imgName = y.toString().substring(2) + "" + (m < 10 ? "0" + m : m) + "" + (rd < 10 ? "0" + rd : rd) + (rh < 10 ? "0" + rh : rh) + "_"+ userInfo.enname +".jpg";
		this.preImgs.push(Monitor.server.imgPath + "R/" + imgName);
	}
	$(".wrap ul li").eq(1).find('img').attr('src', this.preImgs[0]);
	// this.timePre.innerHTML = h +"时";
}

/*************
 * 运行监控获取土壤墒情
 */
Monitor.prototype.showHoureSoil = function() {
	var dt = new Date();
	var y = dt.getFullYear(),
		m = dt.getMonth() + 1,
		d = dt.getDate(),
		h = dt.getHours()-1;
	var rh = h,
		rd = d;
	var tims = [];
	for (var i = 0; i < 6; i++) {
		if (h >= i) {
			var rh = h - i;
		} else {
			var rh = 24 + (h - i);
			var rd = d - 1;
		}
		var userInfo = this.getUserInfo();
		var imgName = y.toString().substring(2) + "" + (m < 10 ? "0" + m : m) + "" + (rd < 10 ? "0" + rd : rd) + (rh < 10 ? "0" + rh : rh) + "_"+ userInfo.enname +".jpg";
		this.soilImgs.push(Monitor.server.imgPath + "S/" + imgName);
		tims.push(y.toString() + "年" + (m < 10 ? "0" + m : m) + "月" + (rd < 10 ? "0" + rd : rd) + "日 " + (rh < 10 ? "0" + rh : rh)+"时");
	}
	$(".heads span").text(tims[0]);
	$(".wrap ul li").eq(2).find('img').attr('src', this.soilImgs[0]);
	// this.timeSoil.innerHTML = h+"时";
}

/************
 * 获取业务统计数量，包括农田、大户、农情、专家、专业服务产品、决策服务产品
 */
Monitor.prototype.getBizCount = function() {
	var oThis = this;
	var userInfo = this.getUserInfo();
	if(userInfo.areacode == '50'){
		//专家注册、农户注册、农情、农田
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.bizcount","CustomParams":{},"Type":2}'},function(data){
			//模型产品
			oThis.modelProducts.text(data[0]['c_profproduct']);
			oThis.modelProducts_.text(data[0]['c_profproduct_m']);
			//作物指标
			oThis.indexC.text(data[0]['c_index']);
			oThis.indexC_.text(data[0]['c_index_m']);
			//产品模型
			oThis.productModel.text(data[0]['c_profproduct']);
			oThis.productModel_.text(data[0]['c_profproduct_m']);
			//气候区划
			// oThis.climateDivision.text(data[0]['']);
			// oThis.climateDivision_.text(data[0]['']);
			//气象灾害
			// oThis.meteorologicalDisaster.text(data[0]['']);
			// oThis.meteorologicalDisaster_.text(data[0]['']);
			//专家经验产品
			oThis.expertExperience.text(data[0]['c_expertproduct']);
			oThis.expertExperience_.text(data[0]['c_expertproduct_m']);
			//注册专家
			oThis.expertRegistration.text(data[0]['c_expert']);
			oThis.expertRegistration_.text(data[0]['c_expert_m']);
			//活跃专家
			oThis.expertsAreActive.text(data[0]['c_expert_score']);
			oThis.expertsAreActive_.text(data[0]['c_expert_score_m']);
			//专家互动
			oThis.expertInteraction.text(data[0]['c_hudong']);
			if (data[0]['c_hudong_m'] == null) {
				oThis.expertInteraction_.text('0');
			}else{
				oThis.expertInteraction_.text(data[0]['c_hudong_m']);
			}
			//注册VIP
			oThis.farmerRegistration.text(data[0]['c_vip']);
			oThis.farmerRegistration_.text(data[0]['c_vip_m']);
			//农户建站
			oThis.farmersStation.text(data[0]['c_workstation']);
			oThis.farmersStation_.text(data[0]['c_workstation_m']);
			//农情上传
			oThis.agriculturalUpload.text(data[0]['c_agrinfo']);
			oThis.agriculturalUpload_.text(data[0]['c_agrinfo_m']);
			//服务农田
			oThis.serviceFarmland.text(data[0]['c_farmland']);
			oThis.serviceFarmland_.text(data[0]['c_farmland_m']);
			//注册农户
			oThis.userRegistration.text(data[0]['c_farmmer']);
			oThis.userRegistration_.text(data[0]['c_farmmer_m']);
			// 大户咨询
			oThis.farmersAdvisoryinfo.text(data[0]['c_farmmerAdvisoryinfo']);
			oThis.farmersAdvisoryinfo_.text(data[0]['c_farmmerAdvisoryinfo_m']);
			// 公共服务产品
			oThis.publicproduct.text(data[0]['c_product']);
			oThis.publicproduct_.text(data[0]['c_product_m']);
			
		});
	}else{
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.bizcount.city","CustomParams":{areacode:"'+ userInfo.areacode +'",areaid:'+ userInfo.areaid +'},"Type":2}'},function(data){
			//模型产品
			oThis.modelProducts.text(data[0]['c_profproduct']);
			oThis.modelProducts_.text(data[0]['c_profproduct_m']);
			//作物指标
			oThis.indexC.text(data[0]['c_index']);
			oThis.indexC_.text(data[0]['c_index_m']);
			//产品模型
			oThis.productModel.text(data[0]['c_productModel']);
			oThis.productModel_.text(data[0]['c_productModel_m']);
			//气候区划
			// oThis.climateDivision.text(data[0]['']);
			// oThis.climateDivision_.text(data[0]['']);
			//气象灾害
			// oThis.meteorologicalDisaster.text(data[0]['']);
			// oThis.meteorologicalDisaster_.text(data[0]['']);
			//专家经验产品
			oThis.expertExperience.text(data[0]['c_expertproduct']);
			oThis.expertExperience_.text(data[0]['c_expertproduct_m']);
			//注册专家
			oThis.expertRegistration.text(data[0]['c_expert']);
			oThis.expertRegistration_.text(data[0]['c_expert_m']);
			//活跃专家
			oThis.expertsAreActive.text(data[0]['c_expert_score']);
			oThis.expertsAreActive_.text(data[0]['c_expert_score_m']);
			//专家回答
			oThis.expertInteraction.text(data[0]['c_hudong']);
			if (data[0]['c_hudong_m'] == null) {
				oThis.expertInteraction_.text('0');
			}else{
				oThis.expertInteraction_.text(data[0]['c_hudong_m']);
			}
			//注册VIP
			oThis.farmerRegistration.text(data[0]['c_vip']);
			oThis.farmerRegistration_.text(data[0]['c_vip_m']);
			//农户建站
			oThis.farmersStation.text(data[0]['c_workstation']);
			oThis.farmersStation_.text(data[0]['c_workstation_m']);
			//农情上传
			oThis.agriculturalUpload.text(data[0]['c_agrinfo']);
			oThis.agriculturalUpload_.text(data[0]['c_agrinfo_m']);
			//服务农田
			oThis.serviceFarmland.text(data[0]['c_farmland']);
			oThis.serviceFarmland_.text(data[0]['c_farmland_m']);
			//注册农户
			oThis.userRegistration.text(data[0]['c_farmmer']);
			oThis.userRegistration_.text(data[0]['c_farmmer_m']);
			// 大户咨询
			oThis.farmersAdvisoryinfo.text(data[0]['c_farmmerAdvisoryinfo']);
			oThis.farmersAdvisoryinfo_.text(data[0]['c_farmmerAdvisoryinfo_m']);
			// 公共服务产品
			oThis.publicproduct.text(data[0]['c_product']);
			oThis.publicproduct_.text(data[0]['c_product_m']);
		});
	}
}

Monitor.prototype.getCustomTime = function(date) {
	var currentdate= null,
		adjustDate = null,
		seperator1 = "-",
		seperator2 = ":",
    	strYear    = date.getFullYear(),
    	strMonth   = date.getMonth() + 1,
    	strDate    = date.getDate(),
    	strHours   = date.getHours(),
    	strMinutes = date.getMinutes(),
    	strSeconds = date.getSeconds();
    if (strMonth >= 1 && strMonth <= 9) {
    	strMonth = "0" + strMonth;
    }
    if (strDate >= 1 && strDate <= 9) {
    	strDate = "0" + strDate;
    }
    if (strHours <= 9) {
    	strHours = "00";
    	strMinutes = "00";
    	strSeconds = "00";
    }
	currentdate = strYear + seperator1 + strMonth + seperator1 + strDate + ' ' + strHours + seperator2 + strMinutes + seperator2 + strSeconds;
    return currentdate;
}

Monitor.prototype.getLessTime = function(date, type) {
	var adjustDate = null,
		currentdate = null;
	var time = date.split('-'),
		strYear = Number(time[0]),
		strMonth= Number(time[1]);
	if (type == 'star') {
		adjustDate  = strYear + '/' + strMonth + '/01 00:00:00';
		currentdate = new Date(adjustDate);
	} else if (type == 'end') {
		strMonth += 1;
		if (strMonth > 12) {
	    	strYear = strYear + 1;
	    	strMonth = "01";
	    }
		adjustDate = (new Date(strYear + '/' + strMonth + '/01 23:59:59')).getTime();
    	currentdate = new Date(adjustDate - 24 * 60 * 60 * 1000 * 1);
	}

	return currentdate;
}

// 统计筛选
Monitor.prototype.getTarget = function(startdate, enddate, queryType){
	// startdate - 开始时间, enddate - 结束时间, queryType - 获取数据类型 [0 - 总数 | 1 - 自定义]
	var oThis = this;
	var userinfo = this.getUserInfo();
	if (queryType == 0) {
		$.post(Monitor.server.apiPath,
			{param:'{"Function":"monitor.getTarget","CustomParams":{areacode:"'+ userinfo.areacode +'",startdate:"2013-01-01 00:00:00",enddate:"'+ enddate +'"},"Type":2}'},
			function(data){
				//模型产品
				oThis.modelProducts.text(data[0]['c_prof']);
				//作物指标
				oThis.indexC.text(data[0]['c_index']);
				//产品模型
				oThis.productModel.text(data[0]['c_productModel']);
				//专家经验产品
				oThis.expertExperience.text(data[0]['c_expertproduct']);
				//注册专家
				oThis.expertRegistration.text(data[0]['c_expert']);
				//活跃专家
				oThis.expertsAreActive.text(data[0]['c_ex_dy']);
				//专家回答
				oThis.expertInteraction.text(data[0]['c_answer']);
				//注册VIP
				oThis.farmerRegistration.text(data[0]['c_vip']);
				//农户建站
				oThis.farmersStation.text(data[0]['c_work']);
				//农情上传
				oThis.agriculturalUpload.text(data[0]['c_agr']);
				//服务农田
				oThis.serviceFarmland.text(data[0]['c_farm']);
				//注册农户
				oThis.userRegistration.text(data[0]['c_user']);
				// 大户咨询
				oThis.farmersAdvisoryinfo.text(data[0]['c_adv']);
				// 公共服务产品
				oThis.publicproduct.text(data[0]['c_pro']);
			}
		);
	}
	if (queryType == 1) {
		$.post(Monitor.server.apiPath,
			{param:'{"Function":"monitor.getTarget","CustomParams":{areacode:"'+ userinfo.areacode +'",startdate:"'+ startdate +'",enddate:"'+ enddate +'"},"Type":2}'},
			function(data){
				//模型产品
				oThis.modelProducts_.text(data[0]['c_prof']);
				//作物指标
				oThis.indexC_.text(data[0]['c_index']);
				//产品模型
				oThis.productModel_.text(data[0]['c_productModel']);
				//专家经验产品
				oThis.expertExperience_.text(data[0]['c_expertproduct']);
				//注册专家
				oThis.expertRegistration_.text(data[0]['c_expert']);
				//活跃专家
				oThis.expertsAreActive_.text(data[0]['c_ex_dy']);
				//专家回答
				oThis.expertInteraction_.text(data[0]['c_answer']);
				//注册VIP
				oThis.farmerRegistration_.text(data[0]['c_vip']);
				//农户建站
				oThis.farmersStation_.text(data[0]['c_work']);
				//农情上传
				oThis.agriculturalUpload_.text(data[0]['c_agr']);
				//服务农田
				oThis.serviceFarmland_.text(data[0]['c_farm']);
				//注册农户
				oThis.userRegistration_.text(data[0]['c_user']);
				// 大户咨询
				oThis.farmersAdvisoryinfo_.text(data[0]['c_adv']);
				// 公共服务产品
				oThis.publicproduct_.text(data[0]['c_pro']);
			}
		);
	}
}


Monitor.prototype.getFarmlands = function(callback){
	var oThis = this;
	var userinfo = this.getUserInfo();
	$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getallfarmland","CustomParams":{areacode:"'+ userinfo.areacode +'"},"Type":2}'},function(data){
		if(callback) callback.call(oThis,data);
	});
}

Monitor.prototype.getAgrInfos = function(callback){
		var oThis = this;
		var userinfo = this.getUserInfo();
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getallagrinfo","CustomParams":{areacode:"'+ userinfo.areacode +'"},"Type":2}'},function(data){
			if(callback) callback.call(oThis,data);
		});
	}

//专家
Monitor.prototype.getExperts = function(limitFirst,limitSecond,callback){
	var oThis = this;
	var userinfo = this.getUserInfo();
	if(userinfo.areacode == '50'){
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getexperts","CustomParams":{limitFirst:'+limitFirst +',limitSecond:'+ limitSecond +'},"Type":2}'},function(data){
			if(callback) callback.call(oThis,data);
		});
	}else{
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getexperts.city","CustomParams":{limitFirst:'+limitFirst +',limitSecond:'+ limitSecond +',areaid:'+ userinfo.areaid +'},"Type":2}'},function(data){
			if(callback) callback.call(oThis,data);
		});
	}
}
//专家 - 首页
Monitor.prototype.getExpertsI = function(){
	var oThis = this;
	var userinfo = this.getUserInfo();
	var	name    = [],
		names   = [],
		HeadImg = [],
		HeadImgs= [];	
	$.post(Monitor.server.apiPath, {param:'{"Function":"monitor.getExpertAdvinfo","CustomParams":{areacode: '+ userinfo.areacode +'},"Type":2}'}, function(data){
		var num = 0;
		for (var x = 0; x < data.length; x++) {
			num = num + 1;
			var html =  "<li>"
							+"<div class=\"infos\">"
								+"<div class=\"left\">"
									+"<img src=\""+ Monitor.server.imgs + data[x].HeadImage +"\">"
									+"<h>"+ data[x].showName +"</h>"
								+"</div>"
								+"<div class=\"right s"+ num +"\">"
									+"<div class=\"xs\">"
										+"<h>"+ data[x].qestion +"</h>"
										+"<p>"+ data[x].comment +"</p>"
										+"<span>"+ data[x].commentTime +"<a href=\"javascript:void(0)\" class=\"more\">详情</a>"
										+"</span>"
									+"</div>";
								+"</div>"
							+"</div>"
						+"</li>";
			$(".expert_box").find('ul').append(html);
		}

		setTimeout(function(){
			$(".expert_box li").find('.more').click(function(){
				$(".xfos").remove();
				var index = $(this).index();
				for (var i = 0; i < 1; i++) {
					var htmls = "<div class=\"xfos\">"
								+"<div class=\"xtit\">"+ $(this).parents('.xs').find('h').text() +"<h>关闭</h></div>"
								+"<div class=\"xcont\">"+ $(this).parents('.xs').find('p').text() +"</div>"
								+"</div>"
								+"<div class=\"xmask\"></div>";
					$("body").append(htmls);
				}
				$(".xtit h").click(function(){
					$(".xfos").remove();
					$(".xmask").remove();
				});
			});
		}, 300);
	});
	//去重
	function toHeavy(Arrs) {
		var newArrs = [], json = {};
		for (var x = 0; x < Arrs.length; x++) {
			if (!json[Arrs[x]]) {					//判断是否为undefined
				if (Arrs[x] == null) {				//空值时赋值
					Arrs[x] = '未分组';
				}
				newArrs.push(Arrs[x]);
				json[Arrs[x]] = 1;					//为undefined时给予赋值
			}
		}
		return newArrs;
	}		
}
//模型产品
Monitor.prototype.getProfproduct = function(){
	var oThis = this;
	var userinfo = this.getUserInfo();
	if (userinfo.areacode == '50') {
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getProfproduct","CustomParams":{areacode:"50"},"Type":2}'},function(data){
			for (var i = 0; i < data.length / 2; i++) {
				var html = "<li><a href=\"javascript:void(0)\"><p>"+ data[i].ProductTitle +"</p><span>"+ data[i].ProductTime +"</span></a></li>";
				$(".model_product ul").append(html);
			}
			$(".model_product li").click(function(){
				$(".xfos").remove();
				var index = $(this).index();
				for (var i = 0; i < 1; i++) {
					var htmls = "<div class=\"xfos\">"
								+"<div class=\"xtit\">"+ data[index].ProductTitle +"<h>关闭</h></div>"
								+"<div class=\"xcont\">"+ data[index].publicInfo +"</div>"
								+"</div>"
								+"<div class=\"xmask\"></div>";
					$("body").append(htmls);
				}
				$(".xtit h").click(function(){
					$(".xfos").remove();
					$(".xmask").remove();
				});
			});
		});
	}else{
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getProfproduct","CustomParams":{areacode:"'+ userinfo.areacode +'",areaid:'+ userinfo.areaid +'},"Type":2}'},function(data){
			for (var i = 0; i < data.length / 2; i++) {
				var html = "<li><a href=\"javascript:void(0)\"><p>"+ data[i].ProductTitle +"</p><span>"+ data[i].ProductTime +"</span></a></li>";
				$(".model_product ul").append(html);
			}
			$(".model_product li").click(function(){
				$(".xfos").remove();
				var index = $(this).index();
				for (var i = 0; i < 1; i++) {
					var htmls = "<div class=\"xfos\">"
								+"<div class=\"xtit\">"+ data[index].ProductTitle +"<h>关闭</h></div>"
								+"<div class=\"xcont\">"+ data[index].publicInfo +"</div>"
								+"</div>"
								+"<div class=\"xmask\"></div>";
					$("body").append(htmls);
				}
				$(".xtit h").click(function(){
					$(".xfos").remove();
					$(".xmask").remove();
				});
			});
		});
	}
}
//专家产品
Monitor.prototype.getExpertproduct = function(){
	var oThis = this;
	var userinfo = this.getUserInfo();
	if (userinfo.areacode == '50') {
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getExpertproduct","CustomParams":{areacode:"50"},"Type":2}'},function(data){
			for (var i = 0; i < data.length / 2; i++) {
				var html = "<li><a href=\"javascript:void(0)\"><p>"+ data[i].title +"</p><span>"+ data[i].createTime +"</span></a></li>";
				$(".expert_product ul").append(html);
			}
			$(".expert_product li").click(function(){
				$(".xfos").remove();
				var index = $(this).index();
				for (var i = 0; i < 1; i++) {
					var htmls = "<div class=\"xfos\">"
								+"<div class=\"xtit\">"+ data[index].title +"<h>关闭</h></div>"
								+"<div class=\"xcont\">"+ data[index].content +"</div>"
								+"</div>"
								+"<div class=\"xmask\"></div>";
					$("body").append(htmls);
				}
				$(".xtit h").click(function(){
					$(".xfos").remove();
					$(".xmask").remove();
				});
			});
		});
	}else{
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getExpertproduct","CustomParams":{areacode:"'+ userinfo.areacode +'",areaid:'+ userinfo.areaid +'},"Type":2}'},function(data){
			for (var i = 0; i < data.length / 2; i++) {
				var html = "<li><a href=\"javascript:void(0)\"><p>"+ data[i].title +"</p><span>"+ data[i].createTime +"</span></a></li>";
				$(".expert_product ul").append(html);
			}
			$(".expert_product li").click(function(){
				$(".xfos").remove();
				var index = $(this).index();
				for (var i = 0; i < 1; i++) {
					var htmls = "<div class=\"xfos\">"
								+"<div class=\"xtit\">"+ data[index].title +"<h>关闭</h></div>"
								+"<div class=\"xcont\">"+ data[index].content +"</div>"
								+"</div>"
								+"<div class=\"xmask\"></div>";
					$("body").append(htmls);
				}
				$(".xtit h").click(function(){
					$(".xfos").remove();
					$(".xmask").remove();
				});
			});
		});
	}
}


Monitor.prototype.getExpertCount = function(callback){
	var oThis = this;
	var userinfo = this.getUserInfo();
	if(userinfo.areacode == '50'){
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getexpertcount","CustomParams":{},"Type":2}'},function(data){
			if(callback) callback.call(oThis,data);
		});
	}else{
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getexpertcount.city","CustomParams":{areaid:'+ userinfo.areaid +'},"Type":2}'},function(data){
			if(callback) callback.call(oThis,data);
		});
	}
	
}

Monitor.prototype.getVips = function(callback){
	var oThis = this;
	var userinfo = this.getUserInfo();
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getvips","CustomParams":{areacode:"'+ userinfo.areacode +'"},"Type":2}'},function(data){
			if(callback) callback.call(oThis,data);
		});
}

Monitor.prototype.getActiveExperts = function(callback){
	var oThis = this;
	var userinfo = this.getUserInfo();
	if(userinfo.areacode == '50'){
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getactiveexperts","CustomParams":{},"Type":2}'},function(data){
			if(callback) callback.call(oThis,data);
		});
	}else{
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getactiveexperts.city","CustomParams":{areaid:"'+ userinfo.areaid +'"},"Type":2}'},function(data){
			if(callback) callback.call(oThis,data);
		});
	}
}

Monitor.prototype.getProfOfArea = function(callback){
	var oThis = this;
	var userinfo = this.getUserInfo();
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.profofarea","CustomParams":{areacode:"'+ userinfo.areacode +'"},"Type":2}'},function(data){
			if(callback) callback.call(oThis,data);
		});
}

Monitor.prototype.getProfOfCrop = function(callback){
	var oThis = this;
	var userinfo = this.getUserInfo();
	$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.profofcrop","CustomParams":{areacode:"'+ userinfo.areacode +'"},"Type":2}'},function(data){
		if(callback) callback.call(oThis,data);
	});
}

Monitor.prototype.getProfOfAreaAndCrop = function(callback){
	var oThis = this;
	var userinfo = this.getUserInfo();
	$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.profofareaandcrop","CustomParams":{areacode:"'+ userinfo.areacode +'"},"Type":2}'},function(data){
		if(callback) callback.call(oThis,data);
	});
}
Monitor.prototype.getProductCount = function(callback){
	var oThis = this;
	var userInfo = this.getUserInfo();
	if(userInfo.areacode == "50"){
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.productcount","CustomParams":{},"Type":2}'},function(data){
			if(callback) callback.call(oThis,data);
		});
	}else{
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.productcount.city","CustomParams":{areaid:"'+ userInfo.areaid +'"},"Type":2}'},function(data){
			if(callback) callback.call(oThis,data);
		});
	}
	
}
//获取农田的信息
Monitor.prototype.getFarmLandOne = function(id,callback){
	var oThis = this;
	$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getfarmlandone","CustomParams":{id:'+ id +'},"Type":2}'},function(data){
		if(callback) callback.call(oThis,data);
	});
}

//获取大户的信息
Monitor.prototype.getVipOne = function(id,callback){
	var oThis = this;
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getvipone","CustomParams":{id:'+ id +'},"Type":2}'},function(data){
			if(callback) callback.call(oThis,data);
		});
}
//获取单个农情的详细信息
Monitor.prototype.getAgrinfoOne = function(id,callback){
	var oThis = this;
	
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getagrinfoone","CustomParams":{id:'+ id +'},"Type":2}'},function(data){
			setTimeout(function(){
				if(callback) callback.call(oThis,data);
			},200);
		});
}
//获取农情关联的图片地址列表
Monitor.prototype.getAgrImgs = function(id,callback){
	var oThis = this;
		$.post(Monitor.server.apiPath,{param:'{"Function":"monitor.getagrimgs","CustomParams":{id:'+ id +'},"Type":2}'},function(data){
			setTimeout(function(){
			if(callback) callback.call(oThis,data);
			},300);
		});
}
function Pager(opts){
	this.recordCount = opts.recordCount;
	this.currentPageIndex = 1;
	this.sqlLimitFirst = 0;
	this.sqlLimitSecond = this.pageSize;
	this.pageCount = this.recordCount%this.pageSize == 0 ? this.recordCount/this.pageSize : parseInt(this.recordCount/this.pageSize)+1;
	//alert(this.pageCount);
	return this;
}

Pager.prototype.pageSize = 9;
Pager.prototype.currentPageIndex = 1;
Pager.prototype.recordCount;
Pager.prototype.pageCount;
Pager.prototype.pageMode = 0;
Pager.prototype.sqlLimitFirst = 0;
Pager.prototype.sqlLimitSecond = 10;

Pager.prototype.next = function(callback){
	if(this.currentPageIndex<this.pageCount){
		this.currentPageIndex++;
		this.sqlLimitFirst = this.pageSize*(this.currentPageIndex-1);
		if(callback) callback.call(this,true);
	}else{
		if(callback) callback.call(this,false);
	}
}
Pager.prototype.getPageSize = function(){
	return this.pageSize;
}

Pager.prototype.getPageCount = function(){
	return this.pageCount;
}

Pager.prototype.getRecordCount = function(){
	return this.recordCount;
}